package org.exeed.controller;

import org.exeed.aop.tag.Auth;
import org.exeed.bean.ResultBean;
import org.exeed.dto.ModifyTO;
import org.exeed.dto.SignInTO;
import org.exeed.dto.TokenTO;
import org.exeed.entity.SysEntity;
import org.exeed.service.SysService;
import org.exeed.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private SysService sysService;

    @PostMapping("/signIn")
    public ResultBean signIn(@RequestBody SignInTO signInTO) {

        try {
            TokenTO r = userService.signIn(signInTO.getUsername(), signInTO.getPassword());
            if (r != null)
                return ResultBean.succeed(r);
        } catch (Exception e) {
            return ResultBean.defeated("登录失败");
        }

        return ResultBean.defeated("登录失败");

    }

    @Auth
    @PostMapping("/modifyPwd")
    public ResultBean modifyPwd(@RequestBody ModifyTO modifyTO) {

        if (userService.modifyPwd(modifyTO)){
            return ResultBean.succeed();
        }
        return ResultBean.defeated("修改失败！");
    }


}
